﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Maticsoft.Common;
using System.Text;

namespace Lawyer.Web
{
    public partial class login : System.Web.UI.Page
    {
        Lawyer.BLL.UserInfo bll = new Lawyer.BLL.UserInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null)
            {
                Session.Abandon();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string strErr = "";
            string UserName = this.username.Value;
            string Password = this.password.Value;
            string UrlRtn = Request["rtn"] == null ? "" : Request["rtn"].ToString();
            if (UserName.Trim().Length == 0)
            {
                strErr += "User name can't be empty!";
                lblErr.Text = strErr;
                lblErr.Visible = true;
                return;
            }
            if (Password.Trim().Length == 0)
            {
                strErr += "Password can't be empty!";
                lblErr.Text = strErr;
                lblErr.Visible = true;
                return;
            }

            if (bll.Exists(UserName,Password))
            {
                string my = "";
                Model.UserInfo user = bll.GetModel(UserName);
                
                Session["UserName"] = user.UserName;
                Session["UserID"] = user.UserID;
                Session["Type"] = user.Type;
                if (user.Type == 1)
                {
                    //if (UrlRtn !="")
                    //    Response.Redirect(UrlRtn);
                    //else
                    Response.Redirect("admin/admin_dashboard.aspx");
                }
                else
                {
                    //if (UrlRtn != "")
                    //    Response.Redirect(UrlRtn);
                    //else
                    Response.Redirect("dashboard.aspx");
                }

            }
        }
    }
}
